<template class="border">
  <el-dialog :visible="showdialog" :title="title" @close="resetForm">
    <!-- 表单 -->
    <el-form ref="formData" :model="formData" :rules="rules" label-width="150px" class="demo-ruleForm">
      <el-form-item label="企业名称" prop="company">
        <el-input
          v-model="formData.company"
          style="width:400px"
        />
      </el-form-item>
      <el-form-item label="所属公司" prop="shortName">
        <el-input v-model="formData.shortName" style="width:400px" />

      </el-form-item>
      <div class="left">
        https://www.tianyancha.com （在此可查询所属公司全称及简称）
      </div>
      <p />
      <el-form label-width="150px">
        <el-row>
          <el-col>
            <el-form-item label="城市地区">
              <el-select v-model="formData.province">
                <el-option :label="formData.province" :value="formData.province" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item>
              <el-select v-model="formData.city">
                <el-option :label="formData.city" :value="formData.city" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form-item label="方向（企业标签）" prop="tags">
        <el-input v-model="formData.tags" style="width:400px" />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input v-model="formData.remarks" placeholder="请输入" type="textarea" style="width:400px" />
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm">取消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>
</template>

<script>
import { dateCompanys, addCompanys } from '@/api/enterprise'

export default {
  props: {
    showdialog: {
      type: Boolean,
      default: false
    },
    list: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      // formData: {
      //   company: '',
      //   shortName: '',
      //   province: '',
      //   city: '',
      //   tags: '',
      //   remarks: ''
      // },
      // 省
      province: '',
      // 市
      city: '',
      // 区
      district: '',
      ruleForm: {
      },
      rules: {
        company: [
          { required: true, message: '企业名称不能为空', trigger: 'blur' }
        ],
        shortName: [
          { required: true, message: '所属公司不能为空', trigger: 'blur' }
        ],
        tags: [
          { required: true, message: '标签不能为空', trigger: 'blur' }
        ],
        remarks: [
          { required: true, message: '备注不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    title() {
      return this.formData.id ? '编辑部门' : '新增部门'
    },
    formData: {
      set() { },
      get() { return this.list }

    }
  },
  created() {
      // console.log(this.formData, '34343')
    },

  methods: {
    changePro() {

    },
    abc(arr) {
      if (arr.isFamous === 1) {
        arr.isFamous = true
      } else {
        arr.isFamous = false
      }
    },
    async submitForm() {
      // this.abc(this.list)
      if (this.formData.id) {
        if (this.formData.isFamous) {
          this.formData.isFamous = true
          console.log(this.formData.isFamous, '-=-=-=-=-=-')
          const res = await dateCompanys(this.formData)
          this.$emit('update:showdialog', false)
          this.$emit('reAfterAdd')
          this.$message.success('修改信息成功！')
          this.formData = {
        company: '',
        shortName: '',
         province: '',
         city: '',
         tags: '',
         remarks: ''
      }
      this.$refs.formData.resetFields()
        this.$emit('update:showdialog', false)
         console.log(res, '编辑')
        }
      } else {
          // 新增业务

        this.formData.isFamous = true
        this.formData.province = '北京市'
        this.formData.city = '朝阳区'

         await addCompanys(this.formData)
          this.$emit('reAfterAdd')
        this.$message.success('添加成功')
        this.formData = {
        company: '',
        shortName: '',
         province: '',
         city: '',
         tags: '',
         remarks: ''
      }
      this.$refs.formData.resetFields()
        this.$emit('update:showdialog', false)
        }
    },
    resetForm() {
      this.formData = {
        company: '',
        shortName: '',
         province: '',
         city: '',
         tags: '',
         remarks: ''
      }
      this.$refs.formData.resetFields()
        this.$emit('update:showdialog', false)
    }
  }

  }
</script>

<style>
.left {
  margin-left: 150px;

}
</style>

